package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Product;
import com.ruoyi.system.service.IBestsellersService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Newarrival;
import com.ruoyi.system.service.INewarrivalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新品上线配置Controller
 * 
 * @author zhang
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/system/newarrival")
public class NewarrivalController extends BaseController
{
    @Autowired
    private INewarrivalService newarrivalService;

    @Autowired
    private IBestsellersService bestsellersService;

    /**
     * 查询新品上线配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:newarrival:list')")
    @GetMapping("/list")
    public TableDataInfo list(Newarrival newarrival)
    {
        startPage();
        List<Newarrival> list = newarrivalService.selectNewarrivalList(newarrival);
        return getDataTable(list);
    }

    /**
     * 导出新品上线配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:newarrival:export')")
    @Log(title = "新品上线配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Newarrival newarrival)
    {
        List<Newarrival> list = newarrivalService.selectNewarrivalList(newarrival);
        ExcelUtil<Newarrival> util = new ExcelUtil<Newarrival>(Newarrival.class);
        util.exportExcel(response, list, "新品上线配置数据");
    }

    /**
     * 获取新品上线配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:newarrival:query')")
    @GetMapping(value = "/{newarrivalId}")
    public AjaxResult getInfo(@PathVariable("newarrivalId") Long newarrivalId)
    {
        return success(newarrivalService.selectNewarrivalByNewarrivalId(newarrivalId));
    }

    /**
     * 新增新品上线配置
     */
    @PreAuthorize("@ss.hasPermi('system:newarrival:add')")
    @Log(title = "新品上线配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Newarrival newarrival)
    {
        return toAjax(newarrivalService.insertNewarrival(newarrival));
    }

    /**
     * 修改新品上线配置
     */
    @PreAuthorize("@ss.hasPermi('system:newarrival:edit')")
    @Log(title = "新品上线配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Newarrival newarrival)
    {
        return toAjax(newarrivalService.updateNewarrival(newarrival));
    }

    /**
     * 删除新品上线配置
     */
    @PreAuthorize("@ss.hasPermi('system:newarrival:remove')")
    @Log(title = "新品上线配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newarrivalIds}")
    public AjaxResult remove(@PathVariable Long[] newarrivalIds)
    {
        return toAjax(newarrivalService.deleteNewarrivalByNewarrivalIds(newarrivalIds));
    }

    /**
     * 查询所有商品信息配置
     */
    @GetMapping("/products")
    public AjaxResult listProducts() {
        List<Product> list = bestsellersService.selectAllProducts();
        return success(list);
    }
}
